package com.ht.ui;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: He Guohong
 * Date: 2012-03-09
 */
public class GridLabelsPanel extends JPanel {

    int labelNum;

    int cols;

    JLabel[] labels;

    public GridLabelsPanel(int labelNum, int cols) {
        this.labelNum = labelNum;
        this.cols = cols;

        labels = new JLabel[labelNum];
        for (int i = 0; i < labelNum; i++)
            labels[i] = new JLabel();
        reload();
    }

    public void reload() {
        int rows = labelNum / cols;
        this.setBorder(new EmptyBorder(2, 15, 10, 15));
        GridLayout gridLayout = new GridLayout(rows, cols,15,10);
        this.setLayout(gridLayout);
        for (JLabel l : labels) {
            this.add(l);
        }
    }

    public void setLabelFont(Font font) {
        for (JLabel l : labels)
            l.setFont(font);
    }

    public int getLabelNum() {
        return labelNum;
    }

    public int getCols() {
        return cols;
    }

    public JLabel[] getLabels() {
        return labels;
    }
}

